#include <stdio.h>
#include <stdlib.h>

#define max(a,b) ((a)>(b)?(a):(b))
int maxProfit(int* prices, int pricesSize, int fee) {
    int dp[pricesSize][2];
    dp[0][0]=0;
    dp[0][1]=-prices[0];
    int i;
    for( i=1; i < pricesSize; i++ ){
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]+prices[i]-fee);
        dp[i][1]=max(dp[i-1][1],dp[i-1][0]-prices[i]);
    }
    return dp[pricesSize-1][0];
}

int main(){
    int p[]={1,3,2,8,4,9};
    printf("%d\n",maxProfit(p,sizeof(p)/sizeof(int),2));
    return 0;
}
